<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Products extends Model
{
    use HasFactory,SoftDeletes;
    protected $dateFormat='U';
    protected $fillable=['name','price','line_price','num','category_id','cover_pic','banners','units','integral'];

    public function cate()
    {
        return $this->hasOne(Category::class,'id','category_id');
    }

    public function getBannersAttribute($value)
    {
        if(!empty($value)){
            return explode(',',$value);
        }
        return $value;
    }

    public function comment()
    {
        return $this->hasMany(Comments::class,'products_id','id');
    }

    public function collect()
    {
        return $this->hasOne(Collect::class,'products_id','id');
    }
}
